<?php
set_time_limit(0);
include '../config/config.php';
$mysqli = new mysqli($dbhost, $dbuser, $dbpwd, $dbName);
if (!$mysqli->set_charset("utf8")) {printf("Error loading character set utf8: %s\n", $mysqliTwo->error);}
$id=1;
if (isset($_GET['id'])){
    $id=$_GET['id'];
}
$sql="select link,cateid from cai_list where id='".$id."'  limit 0,1 ";
$query = $mysqli->query($sql);
 
if($query->num_rows>0){
    $caiInfo=$query->fetch_array();
    $typeid=$caiInfo['cateid']; // 分类
    $url='https://pc.qq.com'.$caiInfo['link'];
    echo $url;
    echo "<br />";
}else{
    exit;
}

//$url='https://pc.qq.com/detail/12/detail_12.html';
include 'dom.php';
$html = file_get_html($url);
$logo=$html->find('div.detail-logo a img',0);
$logoUrl='http://'.substr($logo->src, 2);
$title=$html->find('h2.detail-name',0)->plaintext;
$score=$html->find('div.detail-info span.detail-score',0)->plaintext;
$downloadLink=$html->find('a.detail-install-normal',0)->href;
$getOtherA=$html->find('ul.detail-other',0);
$updateTimeA=explode('：', $getOtherA->find('li',0)->plaintext);
$updateTimeB=explode('-', trim($updateTimeA[1]));
$updateTime2 = mktime(0, 0, 0, $updateTimeB[1], $updateTimeB[2], $updateTimeB[0]);
$softSizeA=explode('：', $getOtherA->find('li',1)->plaintext);  //软件大小
$softSize=trim($softSizeA[1]);
$versionA=explode('：', $getOtherA->find('li',2)->plaintext);  //软件大小
$version=trim($versionA[1]);

$getOtherB=$html->find('ul.detail-other',1);
$platformA=explode('：', $getOtherB->find('li',0)->plaintext);
$platform=trim($platformA[1]);
$weishuA=explode('：', $getOtherB->find('li',1)->plaintext);
$weishu=trim($weishuA[1]);
$content=$html->find('div.cont-content',0)->innertext;
$content=str_replace('style="display:none;"', '', $content);
$content=str_replace('<span class="show_more_box">&nbsp;...<a href="javascript:void(0)" class="show_more">更多</a></span>', '', $content);
$content=htmlspecialchars(str_replace('&nbsp;&nbsp;<a href="javascript:void(0)" class="hide_more">收起</a>', '', $content));


$keywords=str_replace('腾讯软件中心', '小猪下载', $html->find('meta',3)->content);
$descripton=str_replace('腾讯软件中心', '小猪下载', $html->find('meta[name=description]',0)->content);
$parseUrl=explode('_', $url);
$flagid=str_replace('.html', '', $parseUrl[count($parseUrl)-1]); 
 

 


$sql="select aid from ey_archives where flagid='".$flagid."'  limit 0,1 ";
$query = $mysqli->query($sql);
$arInfo=array();
if($query->num_rows>0){
    $arInfo=$query->fetch_assoc();
    $aid=$arInfo['aid'];
}else{

    $sql="insert into ey_archives (seo_keywords,score,downloadlink,logo,seo_description,typeid,channel,title,softsize,update_time,
        platform,version,flagid) values('".$keywords."','".$score."','".$downloadLink."','".$logoUrl."','".$descripton."','".$typeid."','1','".$title."','".$softSize."'
       ,'".$updateTime2."','".$platform."','".$version."','".$flagid."')";
    
    $mysqli->query($sql);
    
    $sql="select aid from ey_archives where flagid='".$flagid."'  limit 0,1 ";
    $query = $mysqli->query($sql);
    $arInfo=$query->fetch_assoc();
    $aid=$arInfo['aid'];
    
    $sql="insert into ey_article_content(aid,content) values('".$aid."','".$content."')";
    $mysqli->query($sql);
}
$mysqli->close();
 
?>
<script>
window.setTimeout(function(){
	   window.location.href="?id=<?php echo ($id+1); ?>";
	}, 2200);
</script>
